{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "参考地址：https://study.163.com/course/courseLearn.htm?courseId=1005632021#/learn/video?lessonId=1052889361&courseId=1005632021\n",
    "\n",
    "# 浏览器操作\n",
    "## 打开网页"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载 webdriver 方法\n",
    "from selenium import webdriver\n",
    "# 创建 firefox 对象，调用 firefox 浏览器\n",
    "driver = webdriver.Firefox()\n",
    "# 在 firefox 中输入需要访问的url路径\n",
    "driver.get('https://pptwin.com/')\n",
    "driver.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Wait time\n",
    "如需要在操作之间设置停留等待时间，则使用 `time.sleep()` 方法。Time 方法需要导入 time 包，n 为秒数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入 time 包\n",
    "import time\n",
    "\n",
    "from selenium import webdriver\n",
    "driver = webdriver.Firefox()\n",
    "driver.get('https://pptwin.com/')\n",
    "\n",
    "# 设置停留等待时间\n",
    "time.sleep(3)\n",
    "\n",
    "# 立即退出\n",
    "driver.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 页面刷新\n",
    "当执行某些操作，如数据添加后，页面未能及时刷新，可利用`driver.refresh()`方法进行页面刷新，一般与`time.sleep()`方法组合使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入 time 包\n",
    "import time\n",
    "\n",
    "from selenium import webdriver\n",
    "driver = webdriver.Firefox()\n",
    "driver.get('https://pptwin.com/')\n",
    "\n",
    "# 设置停留等待时间\n",
    "time.sleep(3)\n",
    "\n",
    "# 刷新页面\n",
    "driver.refresh()\n",
    "\n",
    "time.sleep(2)\n",
    "driver.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 设置大小\n",
    "如果打开的窗口不是全屏、或者需要设为特定的大小，则可以使用`maxmize_window()`和`set_window_size()`进行调整。如：\n",
    "\n",
    "`maxmize_window()` ：设置全屏\n",
    "\n",
    "`set_window_size()`：设置为固定分辨率大小\n",
    "\n",
    "\n",
    "## 页面截屏\n",
    "\n",
    "测试执行过程中发现缺陷需要截屏时，可利用`set_screenshot_as_file()`方法进行截屏，如：\n",
    "\n",
    "`set_screenshot_as_file('path://to/file')`\n",
    "\n",
    "需要注意的是，此方法截屏是整个对象界面，而不是单独某个区域。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入 time 包\n",
    "import time\n",
    "\n",
    "from selenium import webdriver\n",
    "driver = webdriver.Firefox()\n",
    "driver.get('https://google.com/')\n",
    "driver.maximize_window()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
